package st.business.tepth.business.user.busnumber.workholder.maintain.work.content.standardwork.workdetail;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.bean.DiagnoseBean;

/**
 * @author zhangyu
 * @date 2019/2/12
 */
public class DiagnoseAdapter extends BaseQuickAdapter<DiagnoseBean, BaseViewHolder> {
    private int mStatus;
    private List<DiagnoseBean> mConfirmList = new ArrayList<>();

    public DiagnoseAdapter(int layoutResId,
                           int status, @Nullable List<DiagnoseBean> data) {
        super(layoutResId, data);
        mStatus = status;
    }

    @Override
    protected void convert(BaseViewHolder helper, DiagnoseBean item) {
        helper.setText(R.id.tv_diagnose, item.getName());
        if (mStatus < 3) {
            helper.addOnClickListener(R.id.iv_diagnose_delete);
            helper.addOnClickListener(R.id.tv_add_program);
            if (item.isTemp()) {
                //临时添加的本地诊断不能添加方案
                helper.getView(R.id.tv_add_program).setVisibility(View.GONE);
                helper.getView(R.id.iv_diagnose_delete).setVisibility(View.VISIBLE);
            } else {
                helper.getView(R.id.tv_add_program).setVisibility(View.VISIBLE);
                helper.getView(R.id.iv_diagnose_delete).setVisibility(View.VISIBLE);
            }
        } else {
            //已完成状态
            helper.getView(R.id.iv_diagnose_delete).setVisibility(View.GONE);
            helper.getView(R.id.tv_add_program).setVisibility(View.GONE);
        }
    }


    public void notifyAddData(List<DiagnoseBean> addList) {
        List<DiagnoseBean> tempList = new ArrayList<>();
        if (addList != null) {
            tempList.addAll(0, addList);
        }
        if (mConfirmList != null && !mConfirmList.isEmpty()) {
            tempList.addAll(mConfirmList);
        }
        setNewData(tempList);
    }

    public void addTempData(DiagnoseBean diagnoseBean) {
        addData(0, diagnoseBean);
    }

    public List<DiagnoseBean> getTempList() {
        mConfirmList.clear();
        List<DiagnoseBean> all = getData();
        List<DiagnoseBean> temp = new ArrayList<>();
        for (DiagnoseBean diagnoseBean : all) {
            if (diagnoseBean.isTemp()) {
                temp.add(diagnoseBean);
            } else {
                mConfirmList.add(diagnoseBean);
            }
        }
        return temp;
    }
}
